<!-- 新增/编辑 -->
<template>
  <BaseForm
    style="width: 600px"
    v-model="modelData"
    :fields="fields"
    :fetch="data ? PostMockCommonUpdate : PostMockCommonAdd"
    :afterSuccess="() => refreshList()"
    :extraParams="data ? { id: data.id } : undefined"
  >
  </BaseForm>
</template>
<script lang="ts" setup>
import { FormField } from "@/core/components/form/_types";
import { PostMockCommonAdd, PostMockCommonUpdate } from "@/api-mock";
import { CommonObj, FinallyNext, StrNum } from "@/core/_types";

const props = withDefaults(
  defineProps<{
    data?: CommonObj;
    refreshList?: FinallyNext;
  }>(),
  {}
);
const modelData = reactive<CommonObj>({ ...props.data });
const fields: FormField[] = [
  {
    "label": "备注",
    "type": "input",
    "attrs": {
      "type": "textarea",
      "maxlength": 50
    },
    "prop": "remark"
  },
  {
    "prop": "status",
    "label": "启用状态",
    "type": "input",
    "attrs": {
      "activeText": "启用",
      "inactiveText": "禁用"
    }
  },
  {
    "label": "电话",
    "rules": [
      {
        "message": "请输入正确的11位电话号码",
        "trigger": "change"
      }
    ],
    "attrs": {
      "maxlength": 11
    },
    "prop": "phone",
    "type": "input"
  }
];
</script>
<style lang="scss" scoped></style>